home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Procedure: exportSkinMap
- //
- // Description:
- // This mel script is used to export a weight map for the skinning
- // data for each joint that affects the selected skin.
- //
- // To use, select the skin or skins, and type "exportSkinMap"
- //
- //
- proc int checkForLattice(string $obj) {
-
- string $cpShape[] = `ls -type controlPoint $obj`;
- int $isLattice = 0;
- if (size($cpShape) > 0) {
- if (nodeType($obj) == "lattice") {
- $isLattice = 1;
- }
- } else {
- $cpShape = `listRelatives -pa -type controlPoint $obj`;
- for ($cp in $cpShape) {
- if (nodeType($cp) == "lattice") {
- $isLattice = 1;
- break;
- }
- }
- }
- if ($isLattice) {
- string $warnMsg = ("Skipping "+$obj+": Lattice maps are not supported by Artisan.");
- warning($warnMsg);
- }
- return $isLattice;
- }
-
- proc string convertToFileName(string $skin, string $inf)
- {
- string $infNameForFile;
- string $skinNameForFile;
- string $ibuff[];
- int $numTokens = tokenize($inf,"|",$ibuff);
- for ($ii = 0; $ii < $numTokens; $ii++) {
- $infNameForFile += $ibuff[$ii];
- if ($ii != $numTokens-1) {
- $infNameForFile += "_";
- }
- }
- clear($ibuff);
- int $numTokens = tokenize($skin,"|",$ibuff);
- for ($ii = 0; $ii < $numTokens; $ii++) {
- $skinNameForFile += $ibuff[$ii];
- if ($ii != $numTokens-1) {
- $skinNameForFile += "_";
- }
- }
- return ($infNameForFile+"_"+$skinNameForFile);
- }
-
- global proc int exportSkinWeightMap(string $fileName, string $fileType)
- {
- source "artAttrSkinCallback.mel";
- source "artAttrSkinJointMenu.mel";
-
- // Make sure we are in Skin Paint Weight Tool.
- string $currCtx = `currentCtx`;
- artAttrSkinToolScript 4;
-
- string $artCmd = "artAttrCtx -query -exportfiletype `currentCtx`";
- $fileType = eval( $artCmd );
-
- $fileType = tolower($fileType);
- if ($fileType == "IFF") {
- $fileType = "iff";
- } else if ($fileType == "JPEG") {
- $fileType = "jpg";
- } else if ($fileType == "TIFF") {
- $fileType = "tif";
- } else if ($fileType == "Quantel") {
- $fileType = "qtl";
- } else if ($fileType == "Alias") {
- $fileType = "pix";
- } else if ($fileType == "SoftImage") {
- $fileType = "pic";
- } else if ($fileType == "GIF") {
- $fileType = "gif";
- } else if ($fileType == "RLA") {
- $fileType = "rla";
- } else if ($fileType == "SGI") {
- $fileType = "sgi";
- } else if ($fileType == "EPS") {
- $fileType = "eps";
- }else if ($fileType == "Targa") {
- $fileType = "tga";
- }else if ($fileType == "WindowsBitmap") {
- $fileType = "bmp";
- }else if ($fileType == "QuickTime Image") {
- $fileType = "qtif";
- }else if ($fileType == "QuickDraw") {
- $fileType = "qd";
- }else if ($fileType == "Photoshop") {
- $fileType = "psd";
- }else if ($fileType == "PNG") {
- $fileType = "png";
- }else if ($fileType == "MacPaint") {
- $fileType = "pntg";
- }
-
- // Get the selected skins.
- int $skinCount = 0;
- string $currentSelection[] = `ls -sl`;
- string $skins[];
- string $clusters[];
- int $latticeFound = 0;
- for ($sel in $currentSelection) {
- if (checkForLattice($sel)) {
- $latticeFound = 1;
- continue;
- }
-
- // Find the cluster.
- string $buff[];
- tokenize($sel,".",$buff);
- string $cluster = findRelatedSkinCluster($buff[0]);
- if ("" != $cluster) {
- $skins[$skinCount] = $sel;
- $clusters[$skinCount] = $cluster;
- $skinCount++;
- }
- }
-
- if (0 == $skinCount) {
- if ($latticeFound) {
- error("Lattice maps are not supported by Artisan.");
- } else {
- error("No skins were selected.");
- }
- return 0;
- }
-
- // Find the file and directory name.
- string $buff[];
- tokenize($fileName,"/",$buff);
- string $fn = $buff[size($buff)-1];
- tokenize($fn,"\\",$buff);
- $fn = $buff[size($buff)-1];
- $dir = substring($fileName,1,size($fileName)-size($fn));
- tokenize($fn,".",$buff);
- $fn = $buff[0];
-
- $fileName = ($dir+$fn+".weightMap");
- $fileId = fopen( $fileName, "w" );
- if ($fileId == 0) {
- error("Unable to open the file: " + $fileName);
- return 0;
- }
-
- int $passed = 1;
-
- // Write out a master file that links the joint names to the map names.
- fprint($fileId,"// Exported skin weight map file\n");
- fprint($fileId,"// \n");
- $skinCount = 0;
- int $mapCount = 0;
- for ($skin in $skins) {
- string $infs[] = `skinCluster -q -wi $clusters[$skinCount]`;
- for ($inf in $infs) {
- string $dat = ($skin+"\t"+$inf+"\t");
- string $infName = convertToFileName($skin,$inf);
- string $mapFn = ($fn+"_"+$infName+"."+$fileType);
- $dat += ($mapFn+"\n");
- fprint($fileId,$dat);
- $mapCount++;
- }
- $skinCount++;
- }
-
- if (catch(`fclose $fileId`)) {
- error("Unable to close the file: " + $fileName);
- $passed = 0;
- }
-
- if ($mapCount > 5) {
- string $confirm = `confirmDialog -m ($mapCount+" skin maps will be written to disk. Proceed?") -b "Yes" -b "No" -db "Yes"`;
- if ($confirm != "Yes") {
- sysFile -del $fileName;
- return 0;
- }
- }
-
- // Make a directory to contain the maps.
- string $mapDir = ($dir + $fn);
- if (! `file -q -exists $mapDir` ) {
- workspace -cr $mapDir;
- }
-
- // Export the maps for each joint.
- if ($passed) {
- $skinCount = 0;
- for ($skin in $skins) {
- string $infs[] = `skinCluster -q -wi $clusters[$skinCount]`;
- for ($inf in $infs) {
- // Generate a map name for this influence.
- string $infName = convertToFileName($skin,$inf);
- string $mapFn = ($mapDir+"/"+$fn+"_"+$infName+"."+$fileType);
- if (`file -q -exists $mapFn`) {
- sysFile -del $mapFn;
- }
-
- // Set the influence into the tool.
- string $shortName = artAttrSkinShortName($inf);
- select -r $skin;
- artSkinSelectInfluence( "artAttrCtx", $inf, $shortName );
-
- // Make sure that the file name will not be expanded.
- artAttrCtx -e -expandfilename false `currentCtx`;
-
- // Export the map for that influence now.
- artAttrCtx -e -exportfilesave $mapFn `currentCtx`;
- }
- $skinCount++;
- }
- }
-
- // Go back to the original context.
- setToolTo $currCtx;
- select -r $currentSelection;
-
- return $passed;
- }
-
- global proc exportSkinMap( string $version, string $args[] ) {
-
- if (`about -evalVersion`) {
- confirmDialog
- -m "Exporting of skin maps is not supported in Maya PLE."
- -b "Cancel" -db "Cancel";
- return;
- }
-
- // set the fileBrowser directory to the images dir if it exists
- //
- string $imageDir = (`workspace -q -rd`+"sourceimages\/");
- if (`file -q -ex $imageDir`) {
- workspace -dir $imageDir;
- }
-
- // bring up the file browser dialog so that they can choose a file name
- //
- fileBrowser( "exportSkinWeightMap", "Write Map", "map", 1);
- }
-